//package cn.pa4j.service;
//
//import act.app.ActionContext;
//import cn.hutool.core.date.DateUtil;
//import cn.hutool.json.JSONObject;
//import cn.hutool.json.JSONUtil;
//import cn.pa4j.controller.Global;
//import cn.pa4j.pojo.DataJson;
//import cn.pa4j.pojo.MessageInfo;
//import cn.pa4j.pojo.Port;
//import cn.pa4j.utils.LpUtil;
//import org.osgl.http.H;
//import org.osgl.mvc.annotation.GetAction;
//import org.osgl.mvc.annotation.PostAction;
//import org.osgl.mvc.result.BadRequest;
//
//import javax.inject.Inject;
//
///**
// * Created by 060016 on 2017-11-28.
// */
//public class RestService extends Global {
//
//    @Inject
//    protected ActionContext context;
//
////    @Before
////    public String before() {
////if (false) {
////            try {
////                if (dataJson != null) {
////                    JSONObject jsonObject = JSONUtil.parseObj(dataJson);
////                    DataJson data = jsonObject.toBean(DataJson.class);
////                    //校验appKey
////                    String appKey = data.getAppKey();
////                    Port port = dao.getPort("url");
////                    if ("123".equals(appKey)) {
////                        //记录请求内容
////                        MessageInfo messageInfo = new MessageInfo(context.req().ip(),
////                                "url", data.getBody());
////                        return LpUtil.invoke(port, data.getBody());
////                    } else {
//////                    return "无访问权限";
////                    }
////                } else {
////                    throw new BadRequest("format error");
////                }
////            } catch (Exception e) {
////                throw new BadRequest("format error");
////            }
////        }
////    }
////    @GetAction("/format_error")
////    public String format_error() {
////        return "参数格式不正确";
////    }
//
//    @PostAction("/rest/...")
//    public String rest(String dataJson) {
//        String connection = context.req().header("Connection");
////        response.addHeader("Connection","close");
//        System.out.println(connection);
//        if (dataJson != null) {
//            Port port = dao.getPort(context.req().url());
//            if (port != null) {
//                JSONObject jsonObject = JSONUtil.parseObj(dataJson);
//                DataJson data = jsonObject.toBean(DataJson.class);
//                //校验appKey
//                String appKey = data.getAppKey();
//                if ("123".equals(appKey)) {
//                    //记录请求内容
//                    MessageInfo messageInfo = new MessageInfo(context.req().ip(),
//                            "url", data.getBody());
//                    return LpUtil.invoke(port, data.getBody());
//                } else {
//                    return "无访问权限";
//                }
//            } else {
//                return "请求接口不存在";
//            }
//        } else {
//            return "参数格式不正确";
//        }
//    }
//
////    @PostAction("/rest/{url}")
////    public String rest(String url,String dataJson) {
////        System.out.println(dataJson);
////        System.out.println(url);
////        H.Format format = context.req().contentType();
////        String s = format.contentType();
////        System.out.println(s);
////        return url;
////    }
//
//    @GetAction("/sysTime")
//    public String sysTime() {
//        return DateUtil.now();
//    }
//}
